#define _CRT_SECURE_NO_WARNINGS 1

#include <stdio.h>

int main() {
    int year, month;
    int mons[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
    int day = 0;
    while (scanf("%d %d", &year, &month) != EOF) {
        if ((year % 4 == 0) && (year % 100 != 0) || (year % 400 == 0))
        {
            if (month == 2)
                day = mons[month - 1] + 1;
            else
                day = mons[month - 1];
        }
        else {
            day = mons[month - 1];
        }
        printf("%d\n", day);
    }
    return 0;
}